package mps

import (
	"context"
	openapi "github.com/alibabacloud-go/darabonba-openapi/client"
	mts20140618 "github.com/alibabacloud-go/mts-20140618/client"
	"github.com/gogf/gf/v2/frame/g"
	"github.com/gogf/gf/v2/util/gconv"
)

var ctx = context.Background()

var Mps = &mps{
	Mediainfo: &mediainfoService{},
	Snapshot:  &snapshotService{},
	cfg: cfg{
		AccessKeyId:     g.Cfg().MustGet(ctx, "app.aliyun.accessKeyId").String(),
		AccessKeySecret: g.Cfg().MustGet(ctx, "app.aliyun.accessKeySecret").String(),
		MpsRegionId:     g.Cfg().MustGet(ctx, "app.aliyun.mps.regionId").String(),
		PipelineId:      g.Cfg().MustGet(ctx, "app.aliyun.mps.pipelineId").String(),
		OssLocation:     g.Cfg().MustGet(ctx, "app.aliyun.mps.ossLocation").String(),
		// TemplateId:      "S00000001-200000",
	},
}

type mps struct {
	Mediainfo *mediainfoService
	Snapshot  *snapshotService
	cfg       cfg
}
type cfg struct {
	AccessKeyId         string
	AccessKeySecret     string
	MpsRegionId         string
	PipelineId          string
	OssLocation         string
	DefaultOutputBucket string
	// TemplateId      string
}

func (r *mps) New() *mpsRequestEntity {
	return &mpsRequestEntity{}
}
func (r *mps) createClient() (*mts20140618.Client, error) {
	return mts20140618.NewClient(&openapi.Config{
		AccessKeyId:     &r.cfg.AccessKeyId,
		AccessKeySecret: &r.cfg.AccessKeySecret,
		RegionId:        &r.cfg.MpsRegionId,
	})
}

type mpsRequestEntity struct {
	OssLocation *string `json:"Location"` // 必要参数
	OssBucket   *string `json:"Bucket"`   // 必要参数
	OssObject   *string `json:"Object"`   // 必要参数

	OutputPath *string `json:"output_path,omitempty"` // 输出地址
}
type mpsResponseEntity struct {
	RequestId string      `json:"-"`    // 仅内部调试使用
	Data      interface{} `json:"data"` // 具体信息
}

func (r *mpsResponseEntity) Result(v interface{}) {
	_ = gconv.Scan(r.Data, v)
}

type mpsTask interface {
	Query(requestParam *mpsRequestEntity) (*mpsResponseEntity, error)
}

type mpsFactory interface {
	Create() mpsTask // 创建任务
}
